<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of login
 *
 * @author Trung
 */
class User extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->helper('url');
        $this->config->item('base_url');
    }

    public function index() {

        $this->DangNhap();
    }

    public function DangNhap() {
        $data['title'] = 'Đăng Nhập';
        $data['filename'] = 'dangnhap';
        $this->load->view("taikhoan/view", $data);
    }

    public function QuyenMatKhau() {
        $data['title'] = 'Quên Mật Khẩu';
        $data['filename'] = 'quenmatkhau';
        $this->load->view("taikhoan/view", $data);
    }

    public function DoiMatKhau() {
        $data['title'] = 'Đổi Mật Khẩu';
        $data['filename'] = 'doimatkhau';
        $this->load->view("taikhoan/view", $data);
    }

    public function xulyDangNhap() {
        $this->load->model('m_don_sv');
        $this->load->model("m_user");
        $user = $this->m_user->getUser($_POST['taikhoan'], $_POST['matkhau']);
        
        if ($user == FALSE) {
            $this->DangNhap();
        } else {
          
            $this->session->set_userdata('user', $user);
            $data['user'] = $user;   
             // common::showdata($data);
            if (strlen($user['MaSo']) == 9) {
                $this->load->view('sinhvien/sv-index', $data);
            } else {
                //print_r($data);
                $data['count'] = $this->m_don_sv->getCount(-1);
                $data['count0'] = $this->m_don_sv->getCount(0);
                $data['count4'] = $this->m_don_sv->getCount(1);

                $this->load->view('canbo/cb-index', $data);
            }
        }
    }

    public function xulyDangKy() {
        
    }

    public function xulyQuyenMatKhau() {
        $this->load->model("m_user");

        $user = $this->m_user->getUserEmail($_POST['taikhoan']);

        $this->load->view("taikhoan/thongbao", $user);
    }

    public function DangXuat() {
        $this->session->sess_destroy();
        $this->DangNhap();
    }

    public function Thoat() {
        $this->session->sess_destroy();
        $this->DangNhap();
    }

}

?>
